package ai;

import ai.evaluation.Evaluator;
import structure.Board;
import structure.Move;

public abstract class AI {
	
	private byte color;
	private Board board;
	private Evaluator evaluator;
	
	public static AI create(String className, Evaluator evaluator, byte color, Board board) throws InstantiationException, IllegalAccessException, ClassNotFoundException{
		Class<?> c = Class.forName(className);
		if (!AI.class.isAssignableFrom(c))
			throw new RuntimeException("Invalid AI subclass");
		return ((AI) c.newInstance()).createAI(evaluator, color, board);
	}
	
	protected abstract AI createAI(Evaluator evaluator, byte color, Board board);
	public abstract Move getMove(Board board, byte color);
	public abstract String getName();
	public abstract void play(Move move);
	
	public AI(){}
	
	protected AI(Evaluator evaluator, byte color, Board board){
		this.evaluator = evaluator;
		this.color = color;
		this.board = board;
	}
	
	public float fe(Board board,byte color){
		return evaluator.evaluate(board, color);
	}
	
	public String toString(){
		return "AI : \n\t-name : "+getName()+"\n\t-evaluator : "+evaluator+"\n\t-color : "+color;
	}

	public byte getColor() {
		return color;
	}

	public void setColor(byte color) {
		this.color = color;
	}

	public Board getBoard() {
		return board;
	}

	public void setBoard(Board board) {
		this.board = board;
	}
}
